package com.netdisk.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.netdisk.entity.BaseNetdiskEntity;

/**
 * 父Dao类
 * 
 * @author chenlong 2013-4-13
 */
public abstract class Dao<T extends BaseNetdiskEntity> {

	protected SessionFactory sessionFactory;

	public Session getSession() {
		// 事务必须是开启的，否则获取不到
		return sessionFactory.getCurrentSession();
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Autowired
	@Qualifier("sessionFactory")
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public abstract void save(T obj);

	public abstract void update(T obj);

	public abstract void delete(T obj);

	public abstract List<T> findAll();

	public abstract T findById(String id);

	public abstract List<T> findByTop(int from, int max);
}
